package Controller;

import Util.JDBCUtill;
import Util.StringUtil;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

public class LoginController {
    @FXML
    private TextField usernameField;

    @FXML
    private Button loginBut;
    @FXML
    private Label errorinfo;
    @FXML
    private TextField passwordField;

    @FXML
    void LoginAction(ActionEvent event) throws Exception {
        String username= usernameField.getText();
        String pw= passwordField.getText();
        if(StringUtil.isEmpty(username)){
            errorinfo.setText("用户名不能为空");
            errorinfo.setVisible(true);
            return;
        }
        if(StringUtil.isEmpty(pw)){
            errorinfo.setText("密码不能为空");
            errorinfo.setVisible(true);
            return;
        }
        System.out.println("用户登录中");
        if (JDBCUtill.Login(username,pw)) {
            Main.SharedData.isAdmin =JDBCUtill.isAdm(username);
            System.out.println("loginContRoller的Main.SharedData.isAdmin:"+Main.SharedData.isAdmin);
            Main.changeView("ClassRoom.fxml");
            System.out.println("用户登录成功");

        } else {
            errorinfo.setText("用户名或密码错误");
            errorinfo.setVisible(true);
        }
    }
}
